home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Freeware
/
Read It Later 0.9924
/
read_it_later-0.9924-fx.xpi
/
chrome
/
isreaditlater.jar
/
content
/
ISRILinit.js
< prev
next >
Wrap
Text File
|
2008-10-30
|
11KB
|
333 lines
// --- Master Init Functions --- //
function ISRIL_init() {
}
ISRIL_init.prototype = {
_init : function() {
if (!ISRIL.inited) {
try {
// -- Soft Init -- Items with little chance of failing but useful for displaying error messages nicely -- //
ISRILxul._init();
// -- Get Globals
Components.utils.import("resource://rilglobals/ISRILglobals.js");
// -- Connect to Major Firefox services -- Normally the point failure for startup errors -- //
ISRIL_init.startServices();
ISRIL.Connect(); //Connect to Database
ISRIL_init.loadInVars();
ISRIL_init.addToToolbar();
// --- Init Other Objects --- //
ISRILxul._init_finish();
ISRILpr._init();
ISRILsync._init();
ISRILoffline._init();
ISRIL_init.installUpgrade();
ISRIL_init.preloadCaches();
ISRIL_init.eventsObservers();
ISRIL_init.verify();
ISRIL_init.wrapUp();
} catch(err) {
try {
var msg = err.fileName + ' | ' + err.lineNumber + "\n" + err;
//Try to determine if it's a common error
var errorArgs = {
txt: ISRIL.l('error_startup'),
txt2: msg,
buttonTxt: ISRIL.l('GetHelp'),
hideAll: true,
noCancel: true,
onclk : "ISRILxul.recentWindow().getBrowser().selectedTab = ISRILxul.recentWindow().getBrowser().addTab('http://www.ideashower.com/uncategorized/problem-starting-read-it-later/')",
};
if (err.message.match('nsIJSCID.getService')) {
/*
[Exception... "Component returned failure code: 0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE) [nsIJSCID.getService]ö nsresult: ô0╫80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE)ö location: ôJS frame :: chrome://isreaditlater/content/ISRIL.js :: anonymous :: line 26? data: no]
*/
//Can't connect to bookmark service
//Corrupt bookmarks or Norton 360 Conflicts
errorArgs.txt = ISRIL.l('ErrorAccessBookmarks');
errorArgs.txt2 = ISRIL.l('ErrorCommonProblem');
errorArgs.onclk = "ISRILxul.recentWindow().getBrowser().selectedTab = ISRILxul.recentWindow().getBrowser().addTab('http://www.ideashower.com/uncategorized/read-it-later-cant-access-bookmarks/')";
} else if (err.message.match('nsINavHistoryService.executeQuery')) {
/*
[Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED)
[nsINavHistoryService.executeQuery]ö nsresult: ô0╫8000ffff
(NS_ERROR_UNEXPECTED)ö location: ôJS frame ::
chrome://isreaditlater/content/ISRIL.js :: anonymous :: line 366? data: no]
*/
//Corrupted bookmarks file or changed GUID of RIL folder?
errorArgs.txt = ISRIL.l('ErrorAccessFolder');
errorArgs.txt2 = ISRIL.l('ErrorCommonProblem');
errorArgs.onclk = "ISRILxul.recentWindow().getBrowser().selectedTab = ISRILxul.recentWindow().getBrowser().addTab('http://www.ideashower.com/uncategorized/read-it-later-folder-issues/')";
}
ISRILxul.ListErrorSet(true, errorArgs);
ISRIL_init.startupError = true;
} catch(err2) {
//Major failure, couldn't even display nice popups, so we'll have to do the harsh popup, yikes.
alert( ISRIL.l('error_startup') + "\n\n" + err + "\n\n" + err2 );
ISRIL.d('Startup Error: ' + "\n\n" + err + "\n\n" + err2);
}
}
}
},
startServices : function() {
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
ISRIL.sPrompts = Components
.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
ISRIL.sHistory = Components
.classes["@mozilla.org/browser/nav-history-service;1"]
.getService(Components.interfaces.nsINavHistoryService);
ISRIL.sNotes = Components.classes["@mozilla.org/browser/annotation-service;1"]
.getService(Components.interfaces.nsIAnnotationService);
ISRIL.sUri = Components
.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
ISRIL.sTags = Components
.classes["@mozilla.org/browser/tagging-service;1"]
.getService(Components.interfaces.nsITaggingService);
ISRIL.sIcon = Components
.classes["@mozilla.org/browser/favicon-service;1"]
.getService(Components.interfaces.nsIFaviconService);
ISRIL.ios = Components
.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
ISRIL.json = Components.classes["@mozilla.org/dom/json;1"]
.createInstance(Components.interfaces.nsIJSON);
ISRIL.sDB = Components.classes["@mozilla.org/storage/service;1"]
.getService(Components.interfaces.mozIStorageService);
ISRIL.sOb = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
ISRIL.sBookmarks = Components
.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
.getService(Components.interfaces.nsINavBookmarksService);
},
loadInVars : function() {
// --- Preferances --- //
ISRILprefs.loadDefaults();
// --- Get Read It Later Folder --- //
ISRIL.loadFolder();
},
addToToolbar : function() {
// --- Add Buttons if not on UI --- //
if (!ISRILprefs.prefB('added_to_toolbar') && !ISRILxul.bip('ReadSomething')) {
var firefoxnav = document.getElementById("nav-bar");
var curSet = firefoxnav.currentSet;
if (curSet.indexOf("my-extension-button") == -1) {
var set;
set = firefoxnav.currentSet + ",isRitL-ReadSomething";
firefoxnav.setAttribute("currentset", set);
firefoxnav.currentSet = set;
document.persist("nav-bar", "currentset");
BrowserToolboxCustomizeDone(true);
}
ISRILprefs.setPref('added_to_toolbar', true); //Only tried the first time, otherwise it does it once after they remove it
}
},
installUpgrade : function() {
// -- If First Run -- //
t = true;
if (!ISRILprefs.prefB('installed') || t) {
//Check screen resolution to make sure default list size fits
var maxRows = ISRILxul.maxPageN();
if (maxRows < ISRILprefs.pref('list-page')) {
ISRILprefs.setPref('list-page', maxRows);
}
//Set this version as original install point
ISRILprefs.setPref('install-version', ISRIL.v);
//Set as installed
ISRILprefs.setPref('installed', true);
}
ISRILsync.GetAFeed();
// --- Check Version and show Changelog on update --- //
if (ISRILprefs.pref('version') != ISRIL.v) {
window.addEventListener("load", function() { ISRIL.GoTo(ISRIL.cl, false, 'tab') }, false);
ISRILprefs.setPref('version', ISRIL.v);
}
},
preloadCaches : function() {
ISRIL.GetList();
},
eventsObservers : function() {
ISRIL_init.registerObserver('quit-application-requested');
gBrowser.addProgressListener(ISRIL_init.urlBarListener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_ALL);
ISRIL.sBookmarks.addObserver(ISRIL_init.bookmarkObserver, false);
ISRIL.SetupKeyStrokes();
document.getElementById('sidebar').addEventListener("unload", ISRILxul.SidebarEvent, true);
},
verify : function() {
// --- Check that both checkmarks are not appearing --- //
//if (!ISRILxul.bip('later') || !ISRILxul.bip('mark1')) {
// throw ISRIL.l('error_startup');
//}
},
wrapUp : function() {
ISRILglobals.mainWindow = window;
ISRIL.inited = true;
ISRIL.debug = ISRILprefs.prefB('debug');
ISRILglobals.inited = true;
ISRIL.checkPage();
},
// -- Setup Observers -- //
urlBarListener : {
QueryInterface: function(aIID) {
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
aIID.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_NOINTERFACE;
},
onLocationChange: function(aProgress, aRequest, aURI) {
ISRIL.checkPage(aURI);
},
onStateChange: function() {},
onStatusChange: function() {},
onProgressChange: function() {},
onSecurityChange: function() {},
onLinkIconAvailable: function() {},
},
bookmarkObserver : {
QueryInterface: function(aIID) {
if (aIID.equals(Ci.nsINavBookmarkObserver) ||
aIID.equals(Ci.nsISupports))
return this;
throw Cr.NS_NOINTERFACE;
},
onBeginUpdateBatch: function() { },
onEndUpdateBatch: function() { },
onItemVisited: function() { },
onItemAdded : function(aItemId, aFolder, aIndex) {
if (aFolder == ISRILglobals.folderId && !ISRILglobals.adding && aItemId != ISRILglobals.noSyncId) {
ISRILsync.QueueNew( aItemId );
}
},
onItemRemoved: function(aItemId, aFolder, aIndex) {
if (aFolder == ISRILglobals.folderId && ISRILglobals.ListCache[aItemId] && aItemId != ISRILglobals.noSyncId) {
ISRILsync.QueueUpdate( aItemId , 'read' );
if (ISRILglobals.ListCache[aItemId] == ISRIL.url()) {
ISRIL.checkPage();
}
}
},
onItemMoved: function(aItemId, aOldParent, aOldIndex, aNewParent, aNewIndex) {
if (aOldParent == ISRILglobals.folderId && aNewParent != ISRILglobals.folderId && aItemId != ISRILglobals.noSyncId) {
ISRILsync.QueueUpdate( aItemId , 'read' );
} else if (aNewParent == ISRILglobals.folderId && aItemId != ISRILglobals.noSyncId) {
ISRILsync.QueueNew( aItemId );
}
},
onItemChanged: function(aItemId, aProperty, aIsAnnotationProperty) {
f = PlacesUtils.bookmarks.getFolderIdForItem( aItemId );
if (f == ISRILglobals.folderId && aItemId != ISRILglobals.noSyncId) {
if (aProperty == 'tags') {
ISRILsync.QueueUpdateTags( aItemId );
} else if (aProperty == 'title') {
ISRILsync.QueueUpdate( aItemId , 'update_title' );
}
}
}
},
registerObserver : function(topic) {
ISRIL.sOb.addObserver(ISRIL, topic, false);
},
unregisterObserver : function(topic) {
ISRIL.sOb.removeObserver(ISRIL, topic);
},
// -- Unload -- //
_uninit : function() {
gBrowser.removeProgressListener( ISRIL_init.urlBarListener ); //remove?
ISRIL.sBookmarks.removeObserver( ISRIL_init.bookmarkObserver );
},
}
ISRIL_init = new ISRIL_init();
// --- Onload Events --- //
window.addEventListener("load", function() {ISRIL_init._init();}, false);
window.addEventListener("unload", function() {ISRIL_init._uninit();}, false);